package top.datacluster.basic.algorithm.leetcode.stack;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class LeetCode793 {

    public int[] dailyTemperatures(int[] T) {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> index = new Stack<>();
        int[] result = new int[T.length];
        for (int i = 0; i< T.length; i++){
            while (!stack.isEmpty() && stack.peek() < T[i]){
                int j = index.pop();
                result[j] = i;
            }
            stack.push(T[i]);
            index.push(i);



        }

        return result;
    }
}
